
#include "iostream"
#include "vector"
#include "unordered_map"
#include "unordered_set"
#include "algorithm"
#include "string"
#include "list"
#include "string.h"

class OneLoop{
public:
    std::vector<int> num;
    OneLoop(){
    }
    void run(int n){
        for(int i=0;i<n;i++){
            int a;
            std::cin>>a;
            num.push_back(a);
        }
        int cost=0;
        while(num.size()>1){
            std::sort(num.begin(),num.end(),std::greater<int>());
            auto add=num[num.size()-1]+num[num.size()-2];
            cost+=add;
            num.pop_back();
            num.pop_back();
            num.push_back(add);
        }
        std::cout<<cost<<std::endl;
    }
};
class Solution {
public:
    void run() {

        bool first = true;
        int a;
        while (std::cin>>a) {
            OneLoop loop;
            loop.run(a);
        }
    }
};

int main() {
//    bool cur_num= true;
    Solution().run();
    return 0;
}

